package com.hongkuncheng.cms.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;

public class FormLoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        if (request.getSession().getAttribute("member") == null) {
            String callbackUrl = request.getRequestURL() + "?" + request.getQueryString();
            request.getSession().setAttribute("member_redirect_uri", callbackUrl);
            response.sendRedirect("/member/login");
            return false;
        }
        return HandlerInterceptor.super.preHandle(request, response, handler);
    }

}
